home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / ColorSync 2.5.1 SDK / Sample Code / CSDemo 2.5 / CSDemoSources / winTables.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-09  |  8.5 KB  |  301 lines  |  [TEXT/CWIE]

  1. #include "appGlobals.h"
  2. #include "appMenus.h"
  3. #include "appErrors.h"
  4.  
  5. #include "win.h"
  6. #include "winTables.h"
  7.  
  8. #include "winPictDoc.h"
  9. #include "winAbout.h"
  10. #include "winProfile.h"
  11. #include "winProfileGetSet.h"
  12. #include "winProfList.h"
  13. #include "winProfListGetSet.h"
  14. #include "winProfID.h"
  15. #include "winProfIDGetSet.h"
  16.  
  17.  
  18. /**\
  19. |**| ==============================================================================
  20. |**| PRIVATE FUNCTION PROTOTYPES
  21. |**| ==============================================================================
  22. \**/
  23. void winUpdateMenusDefault    ( winHandle win ) ;
  24. void winMenuDefault            ( winHandle win, long menuResult, Boolean *didit ) ;
  25. void DoNewCommand            ( void ) ;
  26. void DoAboutBoxCommand        ( void ) ;
  27. void DoDefaultProfCommand    ( void ) ;
  28. void DoProfListCommand        ( OSType profileClass ) ;
  29.  
  30.  
  31. /**\
  32. |**| ==============================================================================
  33. |**| PUBLIC GLOBALS
  34. |**| ==============================================================================
  35. \**/
  36. short                 gAllocProcMapCount = 3 ;
  37. AllocProcMapRec     gAllocProcMap[3] = {
  38.                                         { 'PICT', winAllocPictDoc, kProfDocPictSubtype, true, false },
  39.                                         { 'prof', winAllocProfile, kFileSubType, false, false },
  40.                                         { 'pfid', winAllocProfID,  kFileSubType, false, false }
  41.                                        };
  42. UpdateMenusProcPtr    gDefaulltUpdateMenusProc = winUpdateMenusDefault ;
  43. MenuProcPtr            gDefaulltMenuProc = winMenuDefault ;
  44.  
  45.  
  46. /**\
  47. |**| ==============================================================================
  48. |**| PRIVATE FUNCTIONS
  49. |**| ==============================================================================
  50. \**/
  51.  
  52.  
  53. /*------------------------------------------------------------------------------*\
  54.     winUpdateMenusDefault
  55.  *------------------------------------------------------------------------------*
  56.         This routine enables any menus and menu items in the menu bar
  57.         which the application is responsible for handling.
  58.         It is called by:
  59.             InitMenuBar() which is called when the app is intited,
  60.             DoActivateEvent() which is called whenever a window is brought to front, and
  61.             CloseProcPtrs which are called whenever windows are closed 
  62. \*------------------------------------------------------------------------------*/
  63. static void winUpdateMenusDefault ( winHandle win ) 
  64. {
  65.     MenuHandle    theMenu ;
  66.     
  67.     // do the file menu
  68.     theMenu = GetMenuHandle ( mApple ) ;
  69.     EnableItem ( theMenu, kWholeMenu ) ;
  70.     EnableItem ( theMenu, iAbout ) ;    
  71.     
  72.     // do the file menu
  73.     theMenu = GetMenuHandle ( mFile ) ;
  74.     EnableItem ( theMenu, kWholeMenu ) ;
  75.     EnableItem ( theMenu, iNew ) ;
  76.  
  77.     // do the profiles menu
  78.     theMenu = GetMenuHandle ( mProfiles ) ;
  79.     EnableItem ( theMenu, kWholeMenu ) ;
  80.     EnableItem ( theMenu, iDefaultProf ) ;
  81.     EnableItem ( theMenu, iCSFolderPopup ) ;
  82.  
  83.     // do the profile lists menu
  84.     theMenu = GetMenuHandle ( mProfileLists ) ;
  85.     EnableItem ( theMenu, kWholeMenu ) ;
  86.     EnableItem ( theMenu, iCSFolder ) ;
  87.     EnableItem ( theMenu, iCSFolderMntr ) ;
  88.     EnableItem ( theMenu, iCSFolderPrtr ) ;
  89.     EnableItem ( theMenu, iCSFolderScnr ) ;
  90. }
  91.  
  92.  
  93. /*------------------------------------------------------------------------------*\
  94.     winMenuDefault
  95.  *------------------------------------------------------------------------------*
  96.         This is a MenuProcPtr for the About window.
  97.         This routine dispatches any menu commands that the window can handle
  98.         to the appropriate function.
  99.         For the About window, the only need menu command is File:Close 
  100.         This ProcPtr is envoked by CallWinMenuProc() which is called by:
  101.             HandleMenuCommand() which dispatches all menu events.
  102. \*------------------------------------------------------------------------------*/
  103. static void winMenuDefault ( winHandle win, long menuResult, Boolean *didit )
  104. {
  105.     short            menuID;
  106.     short            menuItem;
  107.     
  108.     *didit = true ;
  109.     menuID   = HiWrd(menuResult) ;
  110.     menuItem = LoWrd(menuResult) ;
  111.     switch ( menuID )
  112.     {
  113.         case mApple:
  114.             switch ( menuItem )
  115.             {
  116.                 case iAbout:
  117.                     DoAboutBoxCommand() ;
  118.                     break;
  119.                 default :
  120.                     *didit = false ;
  121.                     break ;
  122.             }
  123.             break;
  124.  
  125.         case mFile:
  126.             switch ( menuItem )
  127.             {
  128.                 case iNew:                // make a new document
  129.                     DoNewCommand() ;
  130.                     break;
  131.                     
  132.                 default :
  133.                     *didit = false ;
  134.                     break ;
  135.             }
  136.             break;
  137.             
  138.         case mProfiles:
  139.             switch ( menuItem )
  140.             {
  141.                 case iDefaultProf:
  142.                     DoDefaultProfCommand() ;
  143.                     break;
  144.                 default :
  145.                     *didit = false ;
  146.                     break ;
  147.             }
  148.             break;
  149.  
  150.         case mProfileLists:
  151.             switch ( menuItem )
  152.             {
  153.                 case iCSFolder:
  154.                     DoProfListCommand( 0 ) ;
  155.                     break;
  156.                 case iCSFolderMntr:
  157.                     DoProfListCommand(cmDisplayClass) ;
  158.                     break;
  159.                 case iCSFolderPrtr:
  160.                     DoProfListCommand(cmOutputClass) ;
  161.                     break;
  162.                 case iCSFolderScnr:
  163.                     DoProfListCommand(cmInputClass) ;
  164.                     break;
  165.                 case iCSFolderName:
  166.                     DoProfListCommand(cmNamedColorClass) ;
  167.                     break;
  168.                 default :
  169.                     *didit = false ;
  170.                     break ;
  171.             }
  172.             break;
  173.  
  174.         default :
  175.             *didit = false ;
  176.             break ;
  177.     }
  178.     HiliteMenu(0) ;        // Unhighlight whatever MenuSelect or MenuKey hilited
  179. }
  180.  
  181.  
  182.  
  183. /*------------------------------------------------------------------------------*\
  184.     DoNewCommand
  185.  *------------------------------------------------------------------------------*
  186.         This routine handles the File:New command for the application.
  187.         It is not yet implimented but in principle, it should create a new
  188.         winHandle, and call its OpenProcPtr got get it going.
  189.         It is called by:
  190.             HandleMenuCommand() which dispatches all menu events.
  191. \*------------------------------------------------------------------------------*/
  192. static void DoNewCommand ( void ) 
  193. {
  194.     OSErr            err = noErr ;
  195.     winHandle        win;
  196.  
  197.     // create a new winHandle of the propper type
  198.     err = NewWinHandle( &win, winAllocPictDoc ) ;
  199.     WarnIfErr( err ) ;
  200.     if (err) return ;
  201.  
  202.     err = CallWinNewProc( win ) ;
  203.     if ( err != noErr )
  204.         DisposeWinHandle( win ) ;
  205.  
  206.     if ( err == kWasAlreadyOpen )
  207.         err = noErr ;
  208. }
  209.  
  210.  
  211. /*------------------------------------------------------------------------------*\
  212.     DoAboutBoxCommand
  213.  *------------------------------------------------------------------------------*
  214.         This routine handles the Apple:About command for the application.
  215.         It creates a new winHandle, sets its NewProcPtr, and then 
  216.         calls the NewProcPtr to get it going.
  217.         It is called by:
  218.             HandleMenuCommand() which handles all menu events.
  219. \*------------------------------------------------------------------------------*/
  220. static void DoAboutBoxCommand ( void ) 
  221. {
  222.     OSErr            err = noErr ;
  223.     winHandle        win;
  224.  
  225.     // create a new winHandle of the propper type
  226.     err = NewWinHandle( &win, winAllocAbout ) ;
  227.     WarnIfErr( err ) ;
  228.     if (err) return ;
  229.  
  230.     err = CallWinNewProc( win ) ;
  231.     if ( err != noErr )
  232.         DisposeWinHandle( win ) ;
  233.  
  234.     if ( err == kWasAlreadyOpen )
  235.         err = noErr ;
  236. }
  237.  
  238.  
  239. /*------------------------------------------------------------------------------*\
  240.     DoDefaultProfCommand
  241.  *------------------------------------------------------------------------------*
  242.         This routine handles the Profile:Default Profile command for the application.
  243.         It creates a new winHandle, sets its OpenProcPtr, and then 
  244.         calls the OpenProcPtr to get it going.
  245.         It is called by:
  246.             HandleMenuCommand() which handles all menu events.
  247. \*------------------------------------------------------------------------------*/
  248. static void DoDefaultProfCommand ( void ) 
  249. {
  250.     OSErr            err = noErr ;
  251.     winHandle        win;
  252.                 
  253.     // create a new winHandle of the proper type
  254.     err = NewWinHandle( &win, winAllocProfile ) ;
  255.     WarnIfErr( err ) ;
  256.     if (err) return ;
  257.                 
  258.     SetProfileRef( win, nil ) ;
  259.     SetWinSubtype( win, kSysProfSubType ) ;    // set subtype
  260.                 
  261.     err = CallWinOpenProc( win ) ;
  262.     if ( err != noErr )            //if an error occured
  263.         DisposeWinHandle( win ) ;
  264.         
  265.     if ( err == kWasAlreadyOpen )
  266.         err = noErr;
  267. }
  268.  
  269.  
  270. /*------------------------------------------------------------------------------*\
  271.     DoProfListCommand
  272.  *------------------------------------------------------------------------------*
  273.         This routine handles the Profile:CS Folder command for the application.
  274.         It creates a new winHandle, sets its OpenProcPtr, and then 
  275.         calls the OpenProcPtr to get it going.
  276.         It is called by:
  277.             HandleMenuCommand() which handles all menu events.
  278. \*------------------------------------------------------------------------------*/
  279. static void DoProfListCommand ( OSType profileClass ) 
  280. {
  281.     OSErr            err = noErr ;
  282.     winHandle        win;
  283.     
  284.     // create a new winHandle of the proper type
  285.     err = NewWinHandle( &win, winAllocProfList ) ;
  286.     WarnIfErr( err ) ;
  287.     if (err) return ;
  288.  
  289.     // set the subtype of the winHandle so that the correct search is done
  290.     SetWinSubtype( win, profileClass ) ;    // set subtype
  291.     
  292.     err = CallWinNewProc( win ) ;
  293.     if ( err != noErr )
  294.         DisposeWinHandle( win ) ;
  295.  
  296.     if ( err == kWasAlreadyOpen )
  297.         err = noErr;
  298. }
  299.  
  300.  
  301.